<?php

namespace Home\Model;
use Think\Model;

class BaseModel extends Model
{
    public function store($data){

        if ($this->create($data)){
//            echo 1;die;

            $action=isset($data[$this->pk])?'save':'add';
            //执行add返回自增id，save返回 1  0
            if (empty($data[$this->pk])){
                $this->add();
                return['valid'=>'success','msg'=>'操作成功'];exit;
            }
            $res = $this->$action($data);

            return['valid'=>'success','msg'=>'操作成功','data'=>$res];
        }else{
            return['valid'=>'failed','msg'=>$this->getError()];
        }
    }
}